<?php
/**
 * 前台用户登录中心
 * @author Administrator
 *
 */
class AccountsController extends Zend_Controller_Action {
	private $Cms_session;
	private $api;
	
	public function init() {
		$this->_helper->viewRenderer->setNoRender ();
		$this->Cms_session = Zend_Registry::get ( 'CmsSession' );
		$this->api = new Cms_Apidoc ();
		$this->api->setBaseName ( '登录中心' );
		$this->api->setBaseDesc ( '
			登录中心 使用方法：
			请求方法：post
			参数：
			passport：用户名；
			password:密码；
		' );
	}
	
	/**
	 * 网站登录页面
	 */
	public function indexAction() {
	
	}
	
	/**
	 * 前台登录
	 */
	public function loginAction() {
		if (isset ( $_POST ['passport'] ) && isset ( $_POST ['password'] )) {
			$User_db = new DB_Members ();
			$User_info = $User_db->loadInfo ( 'uid,passport,username,last_login_time', array ('passport = ?' => $_POST ['passport'], 'password = ?' => md5 ( $_POST ['password'] ) ) );
			if ($User_info ['uid']) {
				//更新用户最后登陆时间
				$User_db->updateByPrimary ( array ('last_login_time' => date ( "Y-m-d H:i:s", time () ), 'last_login_ip' => $_POST ['onlineip'] ), $User_info ['uid'] );
				
				//设置加密信息
				$User_info ['authcode'] = $this->Cms_session->expatCookieAuth ( $User_info );
				$this->api->setSucReStatus ( '登陆成功' );
				$this->api->setResult ( $User_info );
			} else {
				$this->api->setErrReStatus ( '登陆失败，用户名或者密码错误' );
			}
			$this->api->buildAPI ();
		}
	}
	
	/**
	 * 显示一个图片验证码
	 */
	public function imgcodeAction() {
		$ImgCode = new Cms_ImageCode ();
		$ImgCode->showNumberImageCode ();
	}
}
?>